﻿using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.IBusiness.DTO;
using Coldairarrow.Util;
using Coldairarrow.Util.ClassLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Coldairarrow.Business.PB
{
    public partial interface IPB_MaterialBusiness
    {
        Task<PageResult<PB_Material>> GetDataListAsync(PageInput<PBMaterialConditionDTO> input);
        Task<PageResult<PB_Material>> GetDataListByPDAAsync(PageInput<PDAMaterialInputDTO> input);
        Task<PageResult<PB_MaterialStockNumberDTO>> ThroughMaterialGetDataList(PageInput<QueryPBMaterialType> input);

        
        Task<PageResult<PB_Material>> GetDataListByHasRefAsync(PageInput<ConditionDTO> input);
        Task<List<PB_Material>> GetDataListAsync();
        Task<MaterialProductDTO> GetTheDataAsync(string id);
        Task AddDataAsync(PB_MaterialProductDTO data,RedisOptions _redisOptions);
        Task UpdateDataAsync(PB_MaterialProductDTO data, RedisOptions _redisOptions);
        Task DeleteDataAsync(List<string> ids);
        Task AddDataExlAsync(List<PB_Material> list, RedisOptions _redisOptions, MongoDBOptions _mongodbOptions);
        Task<PageResult<PB_MaterialListData>> GetDataSelectAsync(PageInput<ConditionDTO> input);

        Task<PageResult<PB_MaterialDataSelectList>> GetDataSelectListAsync(PageInput<PBMaterialConditionDTO> input,string ParentId);

        Task<List<PB_Material>> GetQueryData(SelectQueryDTO search);

        Task<PageResult<PB_MaterialListDTO>> QueryDataListAsync(PageInput<PBMaterialConditionDTO> input);
        Task<PageResult<PB_MaterialStockDTO>> GetMaterialStockDataListAsync(PageInput<PBMaterialConditionDTO> input);

        Task<List<PB_MaterialDTO>> QueryDataQueryAsync(string MId,string id);

        Task<List<PB_MaterialDTO>> QueryDataQueryDeliverAsync(string MId, string id);

        Task<List<PB_MaterialListDTO>> Selectid(string id);
        Task<PB_Material> GetByCode(string code);
        Task<PB_Material> GetByBarcode(string code);

        IQueryable<T> GetQueryable<T>() where T : class, new();
        List<T> GetQueryableByProductCode<T>(List<string> productCodes) where T : class, new();
        List<T> GetQueryableByProductUsageStatusCode<T>(List<string> productCodes) where T : class, new();
        void AddSetRedis();
        Task<List<PB_MaterialPricDTOList>> GetDataListDTOAsync(PageInput<ConditionDTO> input);
        Task<PageResult<PB_MaterialStockDTO>> GetMaterialStockDataListAsyncs(PageInput<PBMaterialConditionDTO> input);
        Task<PageResult<PB_MaterialDataSelectList>> GetDataSelectProductionListsAsync(PageInput<PBMaterialConditionDTO> input, string parentId);

        #region 设计清单所需物料信息

        /// <summary>
        /// 设计清单导入获取物料分类信息及物料code
        /// </summary>
        /// <returns></returns>
        DesignListMaterialTypeDTO GetDesignListMaterialTypeAsync();

        /// <summary>
        /// 获取单位信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="UnitItems"></param>
        /// <returns></returns>
        List<T> GetUnitItems<T>(List<string> UnitItems) where T : class, new();

        #endregion  
        Task<PB_Material> GetMaterId(string Id);

        /// <summary>
        /// 物料档案选择隶属成品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<PageResult<PB_Material>> GetMaterialProductListAsync(PageInput<PBMaterialConditionDTO> input);

        Task UpdateMaterialUsageStatus(UpdateUsageStatus data);

        #region 物料轨迹跟踪

        /// <summary>
        /// 物料跟踪轨迹
        /// </summary>
        /// <returns></returns>
        Task<PageResult<MaterialTrajectoryDTO>> GetMaterialTrajectoryListAsync(PageInput<MTConditionDTO> input);

        #endregion

    }

    /// <summary>
    /// 生产订单添加明细选择
    /// </summary>
    public class PB_MaterialListData : PB_Material
    {
        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcecureName { get; set; }
    }

    public class PB_MaterialDataSelectList : PB_Material
    {
        /// <summary>
        /// 物料类型名称
        /// </summary>
        public string TypeName { get; set; }
        /// <summary>
        /// 清单Id
        /// </summary>
        public string ProcecureMainId { get; set; }
        /// <summary>
        /// 清单名称
        /// </summary>
        public string ProcecureMainName { get; set; }
        /// <summary>
        /// 设计数量
        /// </summary>
        public double? Nums { get; set; }
        /// <summary>
        /// 生产任务ID
        /// </summary>
        public string ProductionOrderId { get; set; }
        /// <summary>
        /// 生产任务单名称
        /// </summary>
        public string ProductionOrderName { get; set; }

    }

    /// <summary>
    /// 设计清单导入获取物料分类信息及物料code
    /// </summary>
    public class DesignListMaterialTypeDTO
    {
        /// <summary>
        /// 物料分类Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 物料Code
        /// </summary>
        public string MaterialCode { get; set; }
    }

    public class PB_MaterialProductDTO : PB_Material
    {
        /// <summary>
        /// 隶属成品Ids
        /// </summary>
        public List<string> MaterialProductIds { get; set; }
    }

    public class MaterialProductDTO : PB_Material
    {
        public List<ProductMaterialDTO> ProductList { get; set; }

        public List<string> MaterialProductIds { get; set; }
    }

    public class ProductMaterialDTO
    {
        public string Id { get; set; }

        public string MaterialId { get; set; }

        public string Name { get; set; }

        public string Code { get; set; }

        public string Spec { get; set; }

        public string ProductCode { get; set; }
    }

    #region 物料轨迹跟踪Model

    public class MaterialTrajectoryDTO
    {

        /// <summary>
        /// 行Id
        /// </summary>
        public int? RowLine { get; set; }

        /// <summary>
        /// 物料Id
        /// </summary>
        public string  MaterialId { get; set; }

        /// <summary>
        /// 物料编码
        /// </summary>
        public string MaterialCode { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string MaterialName { get; set; }

        /// <summary>
        /// 物料规格
        /// </summary>
        public string MaterialSpec { get; set; }

        /// <summary>
        /// 物料类型Id
        /// </summary>
        public string MaterialTypeId { get; set; }

        /// <summary>
        /// 物料类型名称
        /// </summary>
        public string MaterialTypeName { get; set; }

        /// <summary>
        /// 仓储单位
        /// </summary>
        public string StorageName { get; set; }

        /// <summary>
        /// 重量
        /// </summary>
        public Double? Weight { get; set; }

        /// <summary>
        /// 业务日期
        /// </summary>
        public DateTime? BusinessDate { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 业务数量
        /// </summary>
        public Double? Nums { get; set; }

        /// <summary>
        /// 业务单据号
        /// </summary>
        public string DocumentNo { get; set; }

        /// <summary>
        /// 经手人
        /// </summary>
        public string RealName { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        public int? BusinessType { get; set; }

    }

    public class MTConditionDTO
    {
        public string Condition { get; set; }
        public string Keyword { get; set; }

        /// <summary>
        /// 物料编码或物料二维码
        /// </summary>
        public string MaterialCode { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 经手人
        /// </summary>
        public string RealName { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        public int? BusinessType { get; set; }

    }

    #endregion

}